package com.itheima.exam;

import java.io.*;
import java.net.Socket;

public class TCPClient {
    public static void main(String[] args) throws IOException {
        for (int i =0;i<24;i++) {
            //创建客户端对象
            Socket socket = new Socket("127.0.0.1",8888);
            //获得网络输出流
            OutputStream os = socket.getOutputStream();
            //转成效率高的字节缓冲输出流
            BufferedOutputStream bos = new BufferedOutputStream(os);

            //从本地读取文件的字节缓冲输入流
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream("day15_inter\\fj.jpg"));
            int b;
            //读取
            while ((b=bis.read())!=-1){
                //发送
                bos.write(b);
            }
            //刷新输出流
            bos.flush();
            //发送结束暂时停止输出流,给输出流添加结束标记
            socket.shutdownOutput();

            //获得网络输入流
            InputStream is = socket.getInputStream();
            //转成字符缓冲输入流
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            //打印从服务端返回的信息
            System.out.println(br.readLine());

            //关闭字符缓冲输入流
            br.close();
            //关闭读取本地文件的字节流,也可以使用完就关闭
            bis.close();
            //关闭客户端对象
            socket.close();
        }
    }
}
